package model2;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Title：
 * Description：
 * Created by Myth on 5/15/2017.
 */
@WebServlet(name = "LoginController2",urlPatterns = "/LoginController")
public class LoginController extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获得浏览器发来的信息
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        User loginUser = new User();
        loginUser.setUsername(username);
        loginUser.setPassword(password);
        //调用Model的业务方法，根据返回结果控制页面的跳转
        if (loginUser.check()) {
            HttpSession httpSession = request.getSession();
            httpSession.setAttribute("loginUser", loginUser); //将登录信息放到Session之中
            request.getRequestDispatcher("/WEB-INF/model2/success.jsp").forward(request,response);
        } else {
            request.getRequestDispatcher("/WEB-INF/model2/error.jsp").forward(request,response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
